import { Persistent, BasicKeys } from '/@/utils/cache/persistent'
import { TOKEN_KEY } from '/@/enums/cacheEnum'
import projectSetting from '/@/settings/projectSetting';
import { CacheTypeEnum } from '/@/enums/cacheEnum';

const { permissionCacheType } = projectSetting
const isLocal = permissionCacheType === CacheTypeEnum.LOCAL

// 获取token
export function getToken() {
  return getAuthCache<string>(TOKEN_KEY)
}

// 获取缓存
export function getAuthCache<T>(key: BasicKeys) {
  const fn = isLocal ? Persistent.getLocal : Persistent.getSession
  return fn(key) as T
}

// 设置缓存
export function setAuthCache(key: BasicKeys, value) {
  const fn = isLocal ? Persistent.setLocal : Persistent.setSession
  return fn(key, value, true)
}
